package org.mansion.api.dishes;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import com.alibaba.fastjson.JSONArray;
import com.esotericsoftware.minlog.Log;
import com.mdc.mansion.common.exception.BusinessException;
import com.mdc.mansion.common.response.Result;
import com.mdc.mansion.common.response.ResultCode;
import com.mdc.mansion.common.util.I18nUtil;
import com.mdc.mansion.core.modules.order.RestaurantOrderService;
import com.mdc.mansion.core.modules.restaurant.RestaurantTableService;
import com.mdc.mansion.dataaccess.common.context.ContextHolder;
import com.mdc.mansion.dataaccess.modules.order.entity.RestaurantOrder;
import com.mdc.mansion.dataaccess.modules.restaurant.entity.Restaurant;
import com.mdc.mansion.dataaccess.modules.restaurant.entity.RestaurantTable;
import com.mdc.mansion.dataaccess.modules.restaurant.entity.mo.RestaurantTableMO;

import net.sf.json.JSONObject;

/**
 * 
 * @author admin
 *
 */
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {"classpath:application-config.xml"})
public class Table_Test_case {
	
	@Autowired
    private RestaurantTableService restaurantTableService;
	
	@Autowired
	private RestaurantOrderService restaurantOrderService;

	@Before
	public void setUp() throws Exception {
	}

	/**
	 * 
	 */
	@Test
	public void testGetFreeRestaurantTable() {
		
		List<RestaurantTable> freeTableList = null;
		Map<String,Object> resultMap = new HashMap<String,Object>();
		Restaurant restaurant = new Restaurant();
		try
		{
			restaurant.setId("008ee168fad5410fb446afa71b683316");
			freeTableList = restaurantTableService.getFreeRestaurantTable(restaurant);
			resultMap.put("freeTables",freeTableList);
			JSONObject object = JSONObject.fromObject(resultMap);
        	Log.error(object.toString());
		}catch(Exception e)
		{
			Log.error(e.getMessage());
		}
		
		
		
	}
	
	/**
	 * 
	 */
	@Test
	public void testchangeTable() {
		
		try{
			RestaurantOrder restaurantOrder = new RestaurantOrder();
			restaurantOrder.setRestaurantId("008ee168fad5410fb446afa71b683316");
			restaurantOrder.setRestaurantTableId("722dcbd895b84a2686719a8e1ea9f255");
			restaurantOrder.setSerialNum("553c20911b3e445699074d47b608d375");
			restaurantOrder.setId("d14485facd224d5f9586da3941a6b9c1");
			
			restaurantOrderService.changeTable(restaurantOrder);
			
			Log.info("INFO: 成功");
			
		}catch(Exception e)
		{
			Log.error("ERROR:"+e.getMessage());
		}
	}
	
	/**
	 * 
	 */
	@Test
	public void queryTableStatus() {
		
		try{
//			RestaurantOrder restaurantOrder = new RestaurantOrder();
//			restaurantOrder.setRestaurantId("008ee168fad5410fb446afa71b683316");
//			restaurantOrder.setRestaurantTableId("722dcbd895b84a2686719a8e1ea9f255");
//			restaurantOrder.setSerialNum("553c20911b3e445699074d47b608d375");
//			restaurantOrder.setId("d14485facd224d5f9586da3941a6b9c1");
			JSONArray jsonArray = new JSONArray();
			List<RestaurantTableMO> testList = restaurantTableService.selectRestaurantTableWithStatus("008ee168fad5410fb446afa71b683316", "722dcbd895b84a2686719a8e1ea9f255");
			for (RestaurantTableMO restaurantTableMO : testList) {
                JSONObject jsonObject = new JSONObject();
                jsonObject.put("id", restaurantTableMO.getRestaurantId());
                jsonObject.put("tableId", restaurantTableMO.getRestaurantTableId());
                jsonObject.put("status", restaurantTableMO.getStatus());
                jsonArray.add(jsonObject);
            }
        	Log.error("test:>>>>>>>:"+jsonArray.toJSONString());
			
		}catch(Exception e)
		{ 
			Log.error("ERROR:"+e.getMessage());
		}
	}
	

}
